<!--
 * @Author: Lqq
 * @Date: 2025-07-18 09:03:08
 * @LastEditors: Lqq 46081704@qq.com
 * @LastEditTime: 2025-07-18 09:59:06
 * @FilePath: \questionnaire\src\views\components\UploadPic.vue
 * @Description: 
 * 
 * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. 
-->
<template>
  <el-dialog v-model="dialogVisible" title="上传图片" width="80%">
    <!-- <span>照片</span> -->
    <PhotoUpload v-model="questionData.quesData.metadata.photo.answer" />
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleOk">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup lang="ts">
import { reactive, ref } from "vue"
import PhotoUpload from "@/components/PhotoUpload.vue"
import { getSurveyById, saveSurvey } from "@/db/localDb"

const emit = defineEmits(["register", "ok"])
const dialogVisible = ref(false)
const photo = ref("")
const questionData = reactive({
  quesData: {
    metadata: {
      photo: {
        answer: ""
      }
    }
  }
})

const handleClose = () => {
  console.log("关闭")
}
const handleOk = () => {
  console.log("确定", questionData)

  saveSurvey(JSON.parse(JSON.stringify(questionData)))
    .then(() => {
      console.log("保存成功")
      dialogVisible.value = false
      emit("ok")
    })
    .catch((err) => {
      console.log("保存失败", err)
    })
}

const show = (record: any) => {
  console.log("record", record)
  Object.assign(questionData, JSON.parse(JSON.stringify(record)))
  console.log("questionData", questionData)
  dialogVisible.value = true
}
defineExpose({ show })
</script>

<style scoped>
.dialog-footer {
}
</style>
